package com.ccq.service;


import com.alibaba.fastjson.JSON;
import com.ccq.mapper.CardMapper;
import com.ccq.mapper.DictionMapper;
import com.ccq.mapper.SecondMapper;
import com.ccq.model.Card;
import com.ccq.model.Diction;
import com.ccq.model.Second;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SecondService {
    @Autowired
    private CardMapper cardMapper;

    @Autowired
    private DictionMapper dictionMapper;

    @Autowired
    private SecondMapper secondMapper;

    public String carddata() {
        List<Card> ls = cardMapper.selectCardByid();
        for (int i = 0; i < ls.size(); i++) {
            Card ca = ls.get(i);
            List<Diction> features = dictionMapper.selectDicById(ca.getDicId());
            ca.setFeature(features);
        }
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

    public String deallist(){
        List<Second> ls=secondMapper.selectAllData();
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String searchlist1(String adress,String price,String area,String shape,String times,String nice){
        Second s=new Second();

        if(adress.equals(null)){
            s.setAdress(null);
        }else if(adress.equals("拱墅区")){
            s.setAdress("拱墅区");
        }else if(adress.equals("上城区")){
            s.setAdress("上城区");
        }else if(adress.equals("下城区")){
            s.setAdress("下城区");
        }else if(adress.equals("滨江区")){
            s.setAdress("滨江区");
        }

        if(price.equals(null)){
            s.setPrice(null);
        }else if(price.equals("80")){
            s.setPrice(0);
            s.setPrice1(80);
        }else if(price.equals("150")){
            s.setPrice(80);
            s.setPrice1(150);
        }else if(price.equals("200")){
            s.setPrice(150);
            s.setPrice1(200);
        }else if(price.equals("300")){
            s.setPrice(200);
            s.setPrice1(300);
        }

        if(area.equals(null)){
            s.setArea(null);
        }else if(area.equals(50)){
            s.setArea(0);
            s.setArea(50);
        }else if(area.equals(70)){
            s.setArea(50);
            s.setArea(70);
        }else if(area.equals(90)){
            s.setArea(70);
            s.setArea(90);
        }else if(area.equals(130)){
            s.setArea(90);
            s.setArea(130);
        }

        if(shape.equals(null)){
            s.setShape(null);
        }else if(shape.equals("二室")){
            s.setShape("二室");
        }else if(shape.equals("三室")){
            s.setShape("三室");
        }else if(shape.equals("四室")){
            s.setShape("四室");
        }else if(shape.equals("五室")){
            s.setShape("五室");
        }

        if(times.equals(null)){
            s.setTimes(null);
        }else if(times.equals(50)){
            s.setTimes(0);
            s.setTimes(50);
        }else if(times.equals(100)){
            s.setTimes(50);
            s.setTimes(100);
        }else if(times.equals(200)){
            s.setTimes(100);
            s.setTimes(200);
        }

        if(nice.equals(null)){
            s.setNice(null);
        }else if(nice.equals(200)){
            s.setNice(0);
            s.setNice(200);
        }else if(nice.equals(500)){
            s.setNice(200);
            s.setNice(500);
        }

        List<Second> ls=secondMapper.selectallsource(s);
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

}
